package com.xdf.xzymanagementsystem.aop;

import com.xdf.xzymanagementsystem.cache.EhCacheShiro;
import lombok.extern.slf4j.Slf4j;
import org.aspectj.lang.JoinPoint;
import org.aspectj.lang.annotation.AfterReturning;
import org.aspectj.lang.annotation.Aspect;
import org.aspectj.lang.annotation.Pointcut;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

/**
 * @program: xzy-management-system
 * @description: 权限切面
 * @author: 张柯
 * @create: 2021-04-28 22:29
 **/
@Component
@Aspect
@Slf4j
public class SysPermissionAspect {
    @Autowired
    private EhCacheShiro ehCacheShiro;

    @Pointcut("execution(* com.xdf.xzymanagementsystem.service.SysPermissionService.*nsert*(..))")
    public void cutA() {
    }

    @Pointcut("execution(* com.xdf.xzymanagementsystem.service.SysPermissionService.*pdate*(..))")
    public void cutB() {
    }

    /**
     * 修改权限完成后刷新权限缓存
     *
     * @param arg
     */
    @AfterReturning(value = "cutA()||cutB()", returning = "arg")
    public int refreshCache(JoinPoint joinPoint, int arg) {
        log.error("当前返回值" + arg);
        if (arg > 0) {
           // ehCacheShiro.clear();
        }
        return arg;
    }
}
